<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    body::-webkit-scrollbar {width: 0;}
    .shuo{background-color: #F0F0F0;color: #999999;padding: 2px 4px;margin-bottom: 10px}
    .shuo p{padding-left: 10px}
    .shenren{display: none}
</style>
<body>
<form class="layui-form layui-form-pane" id="operatePage">
    <div class="page-title"><div class="page-title-con"><span>编辑节点审核人</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-first">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>节点名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="rovname" id="rovname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审批类型</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="signtypeDiv"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <div class="layui-input-block shuo" style="">
                            <p>会签审批：所有审批人将同时收到待办流程，只有所有会签成员都审批同意时，流程才将流转到下一个节点。</p>
                            <p>或签审批：所有审批人将同时收到待办流程，只要任一或签成员审批同意，流程就将流转到下一个节点。</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审核人类型</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="shentypeDiv"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item shenren" id="shentype_user">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=userid&type=user&single=2');"></div>
                                <div class="tanxiannei" id="userid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=userid&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="userid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item shenren" id="shentype_user_plain">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>是否依次审批</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="plainDiv"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item shenren" id="shentype_role">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审核人</label>
                        <div class="layui-input-block">
                            <div id="roleid"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item shenren" id="shentype_dept">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=deptid&type=dept&single=2');"></div>
                                <div class="tanxiannei" id="deptid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=deptid&type=dept&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="deptid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item shenren" id="shentype_gang">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审核人</label>
                        <div class="layui-input-block">
                            <div id="gangid"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item shenren" id="shentype_base">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>审核人</label>
                        <div class="layui-input-block">
                            <select id="baseid" name="baseid" lay-filter="baseid" >
                                <option value="">请选择</option>
                            </select>
                            <p class="error" id="baseid_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
<!--            <div class="layui-form-item">-->
<!--                <div class="layui-row layui-col-space10">-->
<!--                    <div class="layui-col-md12">-->
<!--                        <label class="layui-form-label"><text>*</text>是否允许编辑</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <div class="radio-block" id="roveditDiv"></div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
<!--            </div>-->
            <div style="height: 400px"></div>
        </div>
    </div>
</form>
<script>
    var param_sectionnum = getQueryVariable('sectionnum');
    var param_classid = getQueryVariable('classid');


    $("#operatePage").validate({
        rules: {
            rovname: {required: true},
        },
        messages:{
            rovname: {required: "请输入"},
        }
    });
    layui.use(['laytp', 'form', 'table'], function() {
        var form = layui.form, layer = layui.layer,table = layui.table;
        render_input_attr();


        var param_domvalue = $('section[key="'+param_sectionnum+'"] .nonedata', parent.document).text() || '';
        if(param_domvalue){
            var valueObj = JSON.parse(param_domvalue);
        }else{
            var valueObj={
                rovname: '',
                signtype: 1,
                shentype: '',
                users: '',
                rovedit: 0,
                plain: 0,
            };
        }



        if(!valueObj.shentype){
            valueObj.shentype = 'user';
        }

        var shentype;
        facade.ajax({type: 'get', url: ask_flow_class_assist,data:{classid:param_classid,shentype:valueObj.shentype,users:valueObj.users}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#rovname").val(valueObj.rovname);
                var signtype_str = '';
                if(valueObj.signtype == 1){
                    signtype_str += '<input type="radio" name="signtype" lay-filter="signtype" value="1" title="会签" checked>';
                    signtype_str += '<input type="radio" name="signtype" lay-filter="signtype" value="2" title="或签">';
                }else{
                    signtype_str += '<input type="radio" name="signtype" lay-filter="signtype" value="1" title="会签">';
                    signtype_str += '<input type="radio" name="signtype" lay-filter="signtype" value="2" title="或签" checked>';
                }
                $('#signtypeDiv').html(signtype_str);


                var shentype_str = '';
                shentype = res.data.shentype;
                for (var key in shentype){
                    if(valueObj.shentype == key){
                        shentype_str += '<input type="radio" name="shentype" value="'+key+'" lay-filter="shentype" title="'+shentype[key]+'" checked>';
                    }else{
                        shentype_str += '<input type="radio" name="shentype" value="'+key+'" lay-filter="shentype" title="'+shentype[key]+'">';
                    }

                }
                $('#shentypeDiv').html(shentype_str);

                var plain_str = '';
                if(valueObj.plain == 1){
                    plain_str += '<input type="radio" name="plain" value="1" title="是" checked>';
                    plain_str += '<input type="radio" name="plain" value="0" title="否">';
                }else{
                    plain_str += '<input type="radio" name="plain" value="1" title="是">';
                    plain_str += '<input type="radio" name="plain" value="0" title="否" checked>';
                }
                $('#plainDiv').html(plain_str);

                var rovedit_str = '';
                if(valueObj.rovedit == 1){
                    rovedit_str += '<input type="radio" name="rovedit" value="1" title="允许" checked>';
                    rovedit_str += '<input type="radio" name="rovedit" value="0" title="不允许">';
                }else{
                    rovedit_str += '<input type="radio" name="rovedit" value="1" title="允许">';
                    rovedit_str += '<input type="radio" name="rovedit" value="0" title="不允许" checked>';
                }
                $('#roveditDiv').html(rovedit_str);




                if(valueObj.shentype == 'user'){
                    if(data.users_info.length > 0){
                        tan_tags_init('#userid', data.users_info);
                    }
                }
                if(valueObj.shentype == 'dept'){
                    if(data.users_info.length > 0){
                        tan_tags_init('#deptid', data.users_info);
                    }
                }
                var edit_roleid = '';
                if(valueObj.shentype == 'role'){
                    edit_roleid = data.users_info;
                }
                var edit_gangid = '';
                if(valueObj.shentype == 'gang'){
                    edit_gangid = data.users_info;
                }
                var edit_baseid = '';
                if(valueObj.shentype == 'base'){
                    edit_baseid = data.users_info;
                }

                $("#shentype_"+valueObj.shentype).show();

                if(valueObj.shentype == 'user' && valueObj.signtype == 1){
                    $("#shentype_user_plain").show();
                }


                var roleidXmObj = xmselect_duo('roleid', res.data.roleArr, edit_roleid, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#roleid").find('xm-select').removeClass('error');
                    }else{
                        $("#roleid").find('xm-select').addClass('error');
                    }
                });

                var gangidXmObj = xmselect_duo('gangid', res.data.gangArr, edit_gangid, function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#gangid").find('xm-select').removeClass('error');
                    }else{
                        $("#gangid").find('xm-select').addClass('error');
                    }
                });

                var baseid_str = '<option value="">请选择</option>';
                var baseArr = res.data.baseArr;
                for (var key in baseArr){
                    if(edit_baseid == key){
                        baseid_str += '<option value="'+key+'" selected>'+baseArr[key]+'</option>';
                    }else{
                        baseid_str += '<option value="'+key+'">'+baseArr[key]+'</option>';
                    }
                }
                $('#baseid').html(baseid_str);

                render_from();
            }
        });


        form.on('radio(signtype)',function (data) {
            var shentype = $('input[name="shentype"]:checked').val();

            if(data.value == 1 && shentype == 'user'){
                $("#shentype_user_plain").show();
            }else{
                $("#shentype_user_plain").hide();
            }
        });


        form.on('radio(shentype)',function (data) {
            var signtype = $('input[name="signtype"]:checked').val();
            for (var key in shentype){
                $("#shentype_"+key).hide();
            }
            $("#shentype_"+data.value).show();

            if(data.value == 'user' && signtype == 1){
                $("#shentype_user_plain").show();
            }else{
                $("#shentype_user_plain").hide();
            }


        });

        form.on('select(baseid)', function(data){
            if(!data.value){
                $('#baseid_error').show().text('请选择');
                $('#baseid_error').parent().find('input').addClass('select_error');
            }else{
                $('#baseid_error').hide();
                $('#baseid_error').parent().find('input').removeClass('select_error');
            }
        });


        form.on('submit(add)', function(data){
            var validRes = $("#operatePage").valid();

            if(data.field.shentype == 'user'){
                data.field.userid = tan_tags_getvalue("#userid", 'user');
                if(!data.field.userid){
                    $("#userid").parents('.tanxian').addClass('tanerror');
                    $('#userid_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#userid").parents('.tanxian').removeClass('tanerror');
                    $('#userid_tanerror').text('');
                }
            }

            if(data.field.shentype == 'dept'){
                data.field.deptid = tan_tags_getvalue("#deptid", 'dept');
                if(!data.field.deptid){
                    $("#deptid").parents('.tanxian').addClass('tanerror');
                    $('#deptid_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#deptid").parents('.tanxian').removeClass('tanerror');
                    $('#deptid_tanerror').text('');
                }
            }

            if(data.field.shentype == 'role'){
                if(!data.field.roleid){
                    $("#roleid").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#roleid").find('xm-select').removeClass('error');
                }
            }

            if(data.field.shentype == 'gang'){
                if(!data.field.gangid){
                    $("#gangid").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#gangid").find('xm-select').removeClass('error');
                }
            }

            if(data.field.shentype == 'base'){
                if(!data.field.baseid){
                    $('#baseid_error').show().text('请选择');
                    $('#baseid_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#baseid_error').hide();
                    $('#baseid_error').parent().find('input').removeClass('select_error');
                }
            }
            if(!validRes){return false;}


            var rovtitle = '';
            if(data.field.shentype == 'user'){
                data.field.users = data.field.userid;
                rovtitle = tan_tags_getname("#userid", 'user');
            }else if(data.field.shentype == 'dept'){
                data.field.users = data.field.deptid;
                rovtitle = tan_tags_getname("#deptid", 'dept');
            }else if(data.field.shentype == 'role'){
                data.field.users = data.field.roleid;
                rovtitle = $("#roleid").find('.label-content').attr('title');
            }else if(data.field.shentype == 'gang'){
                data.field.users = data.field.gangid;
                rovtitle = $("#gangid").find('.label-content').attr('title');
            }else if(data.field.shentype == 'base'){
                data.field.users = data.field.baseid;
                rovtitle = $("#baseid option:selected").text();
            }else{
                data.field.users = '';
            }


            var dataObj={
                rovname: data.field.rovname,
                signtype: data.field.signtype,
                shentype: data.field.shentype,
                users: data.field.users,
                rovedit: data.field.rovedit,
                plain: data.field.plain,
            };



            var signtypename = dataObj.signtype == 1 ? '会签' : '或签';

            var datastr = JSON.stringify(dataObj);
            $('section[key="'+param_sectionnum+'"] .rovname', parent.document).text('[ '+signtypename+' ] '+dataObj.rovname);
            $('section[key="'+param_sectionnum+'"] .rovtitle', parent.document).text(rovtitle);
            $('section[key="'+param_sectionnum+'"] .nonedata', parent.document).text(datastr);

            if(dataObj.rovname && dataObj.users){
                $('section[key="'+param_sectionnum+'"]', parent.document).removeClass('iserrorsection');
                $('section[key="'+param_sectionnum+'"]', parent.document).find('header').removeClass('iserrorheader');
            }else{
                $('section[key="'+param_sectionnum+'"]', parent.document).addClass('iserrorsection');
                $('section[key="'+param_sectionnum+'"]', parent.document).find('header').addClass('iserrorheader');
            }

            layer_close();
            return false;
        });

    });



</script>
</body>
</html>
